using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using System.Runtime.Remoting.Contexts;
using DevExpress.Xpo;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Validation;
using System.ComponentModel;

namespace DomainComponents.XCRM {
    public class QualifyLeadController : ViewController {
        PopupWindowShowAction qualifyLead;
        private void qualifyLead_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
            e.View = Application.CreateDetailView(Application.CreateObjectSpace(), QualifyLeadParameters.CreateQualifyLeadParameters());
            ((DetailView)e.View).ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;

            //e.View = e.Application.CreateDashboardView(e.Application.CreateObjectSpace(), "ConfirmationMessageView", false);
        }
        private void qualifyLead_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
            ((QualifyLeadParameters)e.PopupWindow.View.CurrentObject).Qualify(((ILead)View.CurrentObject), View.ObjectSpace);
            View.ObjectSpace.CommitChanges();
            if(View is ListView) {
                View.ObjectSpace.Refresh();
            }

            
        }
        public QualifyLeadController() {
            TargetObjectType = typeof(ILead);
            qualifyLead = new PopupWindowShowAction(this, "QualifyLead", PredefinedCategory.View);
            qualifyLead.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
            qualifyLead.Caption = "Qualify Lead...";
            qualifyLead.TargetObjectsCriteria = "Status = 'None'";
            qualifyLead.Execute += new PopupWindowShowActionExecuteEventHandler(qualifyLead_Execute);
            qualifyLead.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(qualifyLead_CustomizePopupWindowParams);
        }
    }
}
